
<?

require_once ("application.list.inc");

global $_GLOBAL_DBH;
global $_OBJECT_IFACE_PANEL;

$_OBJECT_IFACE_PANEL = _app_create_iface_panel ();
$_OBJECT_IFACE_DISPLAY->insert_container ($_OBJECT_IFACE_PANEL);

$indexes = array (
	title=>array (label=>"Title",order=>"DEFAULT",wrapper=>"vmc_icon_project"),
	assigned_user=>array (label=>"Assinged User",order=>"DEFAULT",wrapper=>"vmc_icon_user"),
	total_time=>array (label=>"Total Time",order=>"DEFAULT",wrapper=>"vmc_icon_total_time"),
	status=>array (label=>"Status",order=>"DEFAULT",
			values=>array (
				"active",label=>"Active",
				"inactive"=>"Inactive",
				"hold"=>"Hold",
				"suspended"=>"Suspended",
				"processing"=>"Processing",
				"new"=>"New",
				"assigned"=>"Assigned",
				"started"=>"Started",
				"stopped"=>"Stopped",
				"complete"=>"Complete",
			)),
	date_begin=>array (label=>"Begin Date",order=>"DEFAULT",wrapper=>"vmc_icon_date"),
	date_due=>array (label=>"Due Date",order=>"DEFAULT",wrapper=>"vmc_icon_date"),
);

$object_ctl = "/admin/projects/projects/fs_projects.php?fs_action=view&fs_tab=main&";
$link_options = "";
$list_options = array (
	array (
		label=>"Create A New Project",
		link=>"fs_projects.php?fs_action=addnew"
	),
);

$_OBJECT_IFACE_LIST = _app_create_list_object (array (
		db_conn=>$_GLOBAL_DBH,
		indexes=>$indexes,
		list_count=>"SELECT COUNT(*) FROM projects",
		list_select=>"
		SELECT projects.*,
			CONCAT(last,', ',first) AS owner_user,
			CONCAT(last,', ',first) AS assigned_user,
			(
				SELECT COUNT(id)
				FROM project_tasks
				WHERE project_id=projects.id
			) AS total_tasks,
			SEC_TO_TIME((SELECT SUM(
				CASE project_task_timer.date_end
					WHEN '' THEN UNIX_TIMESTAMP()
					ELSE UNIX_TIMESTAMP(project_task_timer.date_end)
				END - UNIX_TIMESTAMP(project_task_timer.date_begin)) FROM project_task_timer,project_tasks WHERE projects.id=project_tasks.project_id AND project_tasks.id=project_task_timer.task_id)) as total_time
			FROM projects,users
			GROUP BY projects.id",
		list_id=>"lc_projects",
		list_title=>"&nbsp;&raquo;&nbsp;Project List",
		list_options=>$list_options,
		primary_key=>"id",
		primary_relation=>"project_id",
		link_options=>$link_options,
		object_ctl=>$object_ctl
));

$_OBJECT_IFACE_PANEL->insert_container ($_OBJECT_IFACE_LIST);

?>
